<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/sockjs.min.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="js/bootstrap.min.js"></script>
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<script type="text/javascript">
	var websocket =null;
	if (window['WebSocket']) {
		//alert( window.location.host);
		websocket = new WebSocket('ws://' + window.location.host + '/websocket/marco');
	}
	else
		websocket = new SockJS('/websocket/js/marco');
		
	websocket.onopen = function() {
		//alert('Opening');
		websocket.send("");
		//sayMarco();
	};
	websocket.onmessage = function(e) {
		//alert('Received message: '+e.data);
		$('#msg').append("<li>"+e.data+"</li>");
	};
	websocket.onclose = function() {
		alert('Closing');
	};
	function sayMarco() {
		alert('Sending Marco!');
		websocket.send("Marco!");
	}  
	function send(){
		//websocket.send($('input').val());
		$.get("/websocket/chat",{msg:$('input').val()});
		$('input').val('');
	}
</script>
	
</head>
<body>
	<input class="form-controll" type="text">
	<button type="button" class="btn btn-primary" onclick="send()">发送</button><br>
	<ul id="msg">
	</ul>
</body>
</html>